package demo2;

import java.io.IOException;
import java.net.*;

public class Demo {
    public static void main(String[] args) throws IOException {
        //通过UDP发送数据

        //1.创建对象
        DatagramSocket ds = new DatagramSocket();
        String str = "hello";
        byte[] bytes = str.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");
        int port = 10011;
        //2.打包数据
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length,address,port);
        ///3.发送数据
        ds.send(dp);
        //释放资源
        ds.close();

    }
}
